﻿#include "function_detectionThreshold.h"


// Procedure declarations
extern void SSM (HObject ho_image, HObject *ho_region_error, HTuple hv_row1, HTuple hv_column1,
    HTuple hv_row2, HTuple hv_column2, HTuple hv_rgb_hsv, HTuple hv_channel1_low,
    HTuple hv_channel1_high, HTuple hv_channel2_low, HTuple hv_channel2_high, HTuple hv_channel3_low,
    HTuple hv_channel3_high, HTuple hv_no_yes_mask, HTuple hv_mask_character, HTuple *hv_ret,
    HTuple *hv_size_error);



//// Procedures
//void SSM_RGB (HObject ho_image, HObject *ho_region_error, HTuple hv_row1, HTuple hv_column1,
//    HTuple hv_row2, HTuple hv_column2, HTuple hv_r_low, HTuple hv_channel1_high, HTuple hv_channel2_low,
//    HTuple hv_channel2_high, HTuple hv_channel3_low, HTuple hv_channel3_high, HTuple hv_mask_character,
//    HTuple *hv_ret, HTuple *hv_message, HTuple *hv_size_error)
//{

//  // Local iconic variables
//  HObject  ho_Rectangle, ho_ImageReduced, ho_ImageRed;
//  HObject  ho_ImageGreen, ho_ImageBlue, ho_RegionR, ho_RegionG;
//  HObject  ho_RegionRG, ho_RegionB, ho_RegionRGB, ho_ImageGray;
//  HObject  ho_RegionC, ho_RegionDilation;

//  // Local control variables
//  HTuple  hv_Row, hv_Column;


//  GenRectangle1(&ho_Rectangle, hv_row1, hv_column1, hv_row2, hv_column2);
//  ReduceDomain(ho_image, ho_Rectangle, &ho_ImageReduced);

//  Decompose3(ho_ImageReduced, &ho_ImageRed, &ho_ImageGreen, &ho_ImageBlue);

//  Threshold(ho_ImageRed, &ho_RegionR, hv_r_low, hv_channel1_high);

//  Threshold(ho_ImageGreen, &ho_RegionG, hv_channel2_low, hv_channel2_high);


//  Intersection(ho_RegionR, ho_RegionG, &ho_RegionRG);

//  Threshold(ho_ImageBlue, &ho_RegionB, hv_channel3_low, hv_channel3_high);

//  Intersection(ho_RegionRG, ho_RegionB, &ho_RegionRGB);


//  Rgb1ToGray(ho_ImageReduced, &ho_ImageGray);
//  Threshold(ho_ImageGray, &ho_RegionC, hv_mask_character, "max");
//  DilationRectangle1(ho_RegionC, &ho_RegionDilation, 9, 9);


//  Difference(ho_RegionRGB, ho_RegionDilation, &(*ho_region_error));




//  AreaCenter((*ho_region_error), &(*hv_size_error), &hv_Row, &hv_Column);


//  (*hv_ret) = 1;
//  (*hv_message) = "";
//  return;



//}


DetectionThreshold::DetectionThreshold(QDialog* parent, QSettings* qsettings, QString section) : QDialog(parent)
{
    m_qsettings = qsettings;
    m_section = section;

    //m_model_image_path = QCoreApplication::applicationDirPath() + "/" + m_model_image_path;

    this->setWindowTitle(("阈值分割检测"));
    QRect desktop_rect = QApplication::desktop()->geometry();
    double ratio_x = desktop_rect.width()/1920.0;
    double ratio_y = desktop_rect.height()/1080.0;

    move(0,0);
    setFixedSize(1920*ratio_x,1010*ratio_y);



    m_view = new MyQGraphicsView(this);
    m_view->setGeometry(660 * ratio_x, 0, 1000 * 1.25 * ratio_x, 800 * 1.25 * ratio_y);
    m_view->m_graphics_shape_rect = new GraphicsShapeRect(100,100,100,100);
    m_view->m_scene->addItem(m_view->m_graphics_shape_rect);
    QRectF qrectf = m_view->m_graphics_shape_rect->boundingRect();
    row1 = (int)qrectf.y();
    column1 = (int)qrectf.x();
    row2 = (int)(qrectf.y() + qrectf.height());
    column2 = (int)(qrectf.x() + qrectf.width());
    connect(m_view->m_graphics_shape_rect, &GraphicsShapeRect::sendMessage, m_view->m_pixmapItem, &MyQGraphicsPixmapItem::receiveMessage);

    QSize control_size(120*ratio_x,40*ratio_y);

    QWidget* p = new QWidget(this);
    p->move(0*ratio_x,0*ratio_y);
    p->setFixedSize(600*ratio_x,800*ratio_y);

    QGridLayout *qgridLayout = new QGridLayout();
    p->setLayout(qgridLayout);

    int index = 0;

    QSize ButtonSize(160 * ratio_x, 40 * ratio_y);


    m_qcombobox_rgb_hsv = new QComboBox(this);
    m_qcombobox_rgb_hsv->setFixedSize(control_size);
    m_qcombobox_rgb_hsv->addItem("rgb");
    m_qcombobox_rgb_hsv->addItem("hsv");
    qgridLayout->addWidget(m_qcombobox_rgb_hsv, index, 0);
    index++;

    m_qlabel_channel1_low = new QLabel();
    m_qlabel_channel1_low->setText("通道1最小值");
    m_qlabel_channel1_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_channel1_low,index,0);

    m_qspinbox_channel1_low = new QSpinBox();
    m_qspinbox_channel1_low->setFixedSize(control_size);
    m_qspinbox_channel1_low->setMinimum(0);
    m_qspinbox_channel1_low->setMaximum(255);
    m_qspinbox_channel1_low->setReadOnly(true);
    qgridLayout->addWidget(m_qspinbox_channel1_low,index,1);

    m_qslider_channel1_low = new QSlider(Qt::Horizontal);
    m_qslider_channel1_low->setTickPosition(QSlider::NoTicks);
    m_qslider_channel1_low->setSingleStep(1);
    m_qslider_channel1_low->setMinimum(0);
    m_qslider_channel1_low->setMaximum(255);

    qgridLayout->addWidget(m_qslider_channel1_low,index,2);
    index++;

    m_qlabel_channel1_high = new QLabel();
    m_qlabel_channel1_high->setText("通道1最大值");
    m_qlabel_channel1_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_channel1_high,index,0);

    m_qspinbox_channel1_high = new QSpinBox();
    m_qspinbox_channel1_high->setFixedSize(control_size);
    m_qspinbox_channel1_high->setMinimum(0);
    m_qspinbox_channel1_high->setMaximum(255);
    m_qspinbox_channel1_high->setReadOnly(true);
    qgridLayout->addWidget(m_qspinbox_channel1_high,index,1);

    m_qslider_channel1_high = new QSlider(Qt::Horizontal);
    m_qslider_channel1_high->setTickPosition(QSlider::NoTicks);
    m_qslider_channel1_high->setSingleStep(1);
    m_qslider_channel1_high->setMinimum(0);
    m_qslider_channel1_high->setMaximum(255);

    qgridLayout->addWidget(m_qslider_channel1_high,index,2);
    index++;
    m_qlabel_channel2_low = new QLabel();
    m_qlabel_channel2_low->setText("通道2最小值");
    m_qlabel_channel2_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_channel2_low,index,0);

    m_qspinbox_channel2_low = new QSpinBox();
    m_qspinbox_channel2_low->setFixedSize(control_size);
    m_qspinbox_channel2_low->setMinimum(0);
    m_qspinbox_channel2_low->setMaximum(255);
    m_qspinbox_channel2_low->setReadOnly(true);
    qgridLayout->addWidget(m_qspinbox_channel2_low,index,1);

    m_qslider_channel2_low = new QSlider(Qt::Horizontal);
    m_qslider_channel2_low->setTickPosition(QSlider::NoTicks);
    m_qslider_channel2_low->setSingleStep(1);
    m_qslider_channel2_low->setMinimum(0);
    m_qslider_channel2_low->setMaximum(255);

    qgridLayout->addWidget(m_qslider_channel2_low,index,2);
    index++;

    m_qlabel_channel2_high = new QLabel();
    m_qlabel_channel2_high->setText("通道2最大值");
    m_qlabel_channel2_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_channel2_high,index,0);

    m_qspinbox_channel2_high = new QSpinBox();
    m_qspinbox_channel2_high->setFixedSize(control_size);
    m_qspinbox_channel2_high->setMinimum(0);
    m_qspinbox_channel2_high->setMaximum(255);
    m_qspinbox_channel2_high->setReadOnly(true);
    qgridLayout->addWidget(m_qspinbox_channel2_high,index,1);

    m_qslider_channel2_high = new QSlider(Qt::Horizontal);
    m_qslider_channel2_high->setTickPosition(QSlider::NoTicks);
    m_qslider_channel2_high->setSingleStep(1);
    m_qslider_channel2_high->setMinimum(0);
    m_qslider_channel2_high->setMaximum(255);

    qgridLayout->addWidget(m_qslider_channel2_high,index,2);
    index++;


    m_qlabel_channel3_low = new QLabel();
    m_qlabel_channel3_low->setText("通道3最小值");
    m_qlabel_channel3_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_channel3_low,index,0);

    m_qspinbox_channel3_low = new QSpinBox();
    m_qspinbox_channel3_low->setFixedSize(control_size);
    m_qspinbox_channel3_low->setMinimum(0);
    m_qspinbox_channel3_low->setMaximum(255);
    m_qspinbox_channel3_low->setReadOnly(true);
    qgridLayout->addWidget(m_qspinbox_channel3_low,index,1);

    m_qslider_channel3_low = new QSlider(Qt::Horizontal);
    m_qslider_channel3_low->setTickPosition(QSlider::NoTicks);
    m_qslider_channel3_low->setSingleStep(1);
    m_qslider_channel3_low->setMinimum(0);
    m_qslider_channel3_low->setMaximum(255);

    qgridLayout->addWidget(m_qslider_channel3_low,index,2);
    index++;

    m_qlabel_channel3_high = new QLabel();
    m_qlabel_channel3_high->setText("通道3最大值");
    m_qlabel_channel3_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_channel3_high,index,0);
    m_qspinbox_channel3_high = new QSpinBox();
    m_qspinbox_channel3_high->setFixedSize(control_size);
    m_qspinbox_channel3_high->setMinimum(0);
    m_qspinbox_channel3_high->setMaximum(255);
    m_qspinbox_channel3_high->setReadOnly(true);
    qgridLayout->addWidget(m_qspinbox_channel3_high,index,1);

    m_qslider_channel3_high = new QSlider(Qt::Horizontal);
    m_qslider_channel3_high->setTickPosition(QSlider::NoTicks);
    m_qslider_channel3_high->setSingleStep(1);
    m_qslider_channel3_high->setMinimum(0);
    m_qslider_channel3_high->setMaximum(255);

    qgridLayout->addWidget(m_qslider_channel3_high,index,2);


    index++;
    m_qcombobox_no_yes_mask = new QComboBox(this);
    m_qcombobox_no_yes_mask->setFixedSize(control_size);
    m_qcombobox_no_yes_mask->addItem("不屏蔽字符");
    m_qcombobox_no_yes_mask->addItem("屏蔽字符");
    qgridLayout->addWidget(m_qcombobox_no_yes_mask, index, 0);

    index++;
    m_qlabel_mask_low = new QLabel();
    m_qlabel_mask_low->setText("字符屏蔽下限");
    m_qlabel_mask_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_mask_low, index, 0);
    m_qspinbox_mask_low = new QSpinBox();
    m_qspinbox_mask_low->setFixedSize(control_size);
    m_qspinbox_mask_low->setMinimum(0);
    m_qspinbox_mask_low->setMaximum(255);
    qgridLayout->addWidget(m_qspinbox_mask_low, index, 1);


    m_qslider_mask_low = new QSlider(Qt::Horizontal);
    m_qslider_mask_low->setTickPosition(QSlider::NoTicks);
    m_qslider_mask_low->setSingleStep(1);
    m_qslider_mask_low->setMinimum(0);
    m_qslider_mask_low->setMaximum(255);

    qgridLayout->addWidget(m_qslider_mask_low,index,2);
    index++;

    m_qlabel_area_low = new QLabel();
    m_qlabel_area_low->setText("缺陷面积下限");
    m_qlabel_area_low->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_area_low,index,0);
    m_qspinbox_area_low = new QSpinBox();
    m_qspinbox_area_low->setFixedSize(control_size);
    m_qspinbox_area_low->setMinimum(0);
    m_qspinbox_area_low->setMaximum(100000);
    qgridLayout->addWidget(m_qspinbox_area_low, index, 1);
    index++;

    m_qlabel_area_high = new QLabel();
    m_qlabel_area_high->setText("缺陷面积上限");
    m_qlabel_area_high->setFixedSize(control_size);
    qgridLayout->addWidget(m_qlabel_area_high,index,0);
    m_qspinbox_area_high = new QSpinBox();
    m_qspinbox_area_high->setFixedSize(control_size);
    m_qspinbox_area_high->setMinimum(0);
    m_qspinbox_area_high->setMaximum(100000);
    qgridLayout->addWidget(m_qspinbox_area_high, index, 1);
    index++;

    m_pushbutton_save_parameter = new QPushButton(this);
    m_pushbutton_save_parameter->setFixedSize(control_size);
    m_pushbutton_save_parameter->setText("保存参数");
    connect(m_pushbutton_save_parameter, &QPushButton::clicked, this, &DetectionThreshold::saveParameter);
    qgridLayout->addWidget(m_pushbutton_save_parameter, index,0);
    index++;

    m_pushbutton_show_orign_image = new QPushButton(this);
    m_pushbutton_show_orign_image->setFixedSize(control_size);
    m_pushbutton_show_orign_image->setText("显示原图");
    connect(m_pushbutton_show_orign_image, &QPushButton::clicked, this,[=]() {
        Mat image_show = himageToMat(image_in);
        QImage q_image = matToQImage(image_show);
        m_view->setImage(q_image,"");
        return true;
    });
    qgridLayout->addWidget(m_pushbutton_show_orign_image, index,0);

    m_pushbutton_detection = new QPushButton(this);
    m_pushbutton_detection->setFixedSize(control_size);
    m_pushbutton_detection->setText("检测");
    connect(m_pushbutton_detection, &QPushButton::clicked, this, &DetectionThreshold::detectionImage);
    qgridLayout->addWidget(m_pushbutton_detection, index,1);
    index++;

    m_pushbutton_return = new QPushButton(this);
    m_pushbutton_return->setFixedSize(control_size);
    m_pushbutton_return->setText("退出");
    qgridLayout->addWidget(m_pushbutton_return, index, 0);
    connect(m_pushbutton_return, &QPushButton::clicked, this, [=]() {
        this->hide();
        });

    
    try
    {
        m_proc_detection = new HDevProcedure("SSM_HSV");
        m_call_detection = new HDevProcedureCall(*m_proc_detection);
    }
    catch (HDevEngineException& hdev_exception)
    {
        //QMessageBox::information(nullptr, "", hdev_exception.Message());
    }


    loadParameter();
    connect(m_qslider_mask_low, &QSlider::valueChanged, this, [=](int value) {
            m_qspinbox_mask_low->setValue(value);
            saveParameter();
            testImage();
    });
    connect(m_qslider_channel2_low, &QSlider::valueChanged, this, [=](int value) {
            m_qspinbox_channel2_low->setValue(value);
            saveParameter();
            testImage();
    });
    connect(m_qslider_channel2_high, &QSlider::valueChanged, this, [=](int value) {
            m_qspinbox_channel2_high->setValue(value);
            saveParameter();
            testImage();
    });

    connect(m_qslider_channel1_low, &QSlider::valueChanged, this, [=](int value) {
            m_qspinbox_channel1_low->setValue(value);
            saveParameter();
            testImage();

    });
    connect(m_qslider_channel1_high, &QSlider::valueChanged, this, [=](int value) {
            m_qspinbox_channel1_high->setValue(value);
            saveParameter();
            testImage();
    });

    connect(m_qslider_channel3_low, &QSlider::valueChanged, this, [=](int value) {
            m_qspinbox_channel3_low->setValue(value);
            saveParameter();
            testImage();
    });
    connect(m_qslider_channel3_high, &QSlider::valueChanged, this, [=](int value) {
            m_qspinbox_channel3_high->setValue(value);
            saveParameter();
            testImage();
    });
}

DetectionThreshold::~DetectionThreshold()
{
    ;
}


bool DetectionThreshold::detection( HObject image_in, QString& message)
{
  /*  if (m_image.empty())
    {
        message += "检测图像为空 ";
        return false;
    }*/
    try
    {
        HTuple ret ;
        HTuple msg ;
        HTuple size_error;

        SSM(image_in,&region_error,row1,column1,row2,column2,m_rgb_hsv,channel1_low,channel1_high,channel2_low,channel2_high,channel3_low,channel3_high,m_no_yes_mask,m_mask_low,&ret,&size_error);

//        SSM_RGB(image_in,&region_error,row1,column1,row2,column2,r_low,channel1_high,channel2_low,channel2_high,channel3_low,channel3_high,m_mask_low,&ret,&msg,&size_error);




//        // Set the input parameters of the procedure
////        if (!image_in.IsInitialized())
////        {
////            return false;
////        }
//        m_call_detection->SetInputIconicParamObject("image", image_in,row1,column1,row2,column2,r_low,channel1_high,channel2_low,channel2_high,channel3_low,channel3_high


////        m_call_detection->SetInputCtrlParamTuple("row1_offset", row1_offset);
////        m_call_detection->SetInputCtrlParamTuple("column1_offset", column1_offset);
////        m_call_detection->SetInputCtrlParamTuple("row2_offset", row2_offset);
////        m_call_detection->SetInputCtrlParamTuple("column2_offset", column2_offset);
////        m_call_detection->SetInputCtrlParamTuple("column21_offset", column21_offset);
////        m_call_detection->SetInputCtrlParamTuple("column22_offset", column22_offset);

////        m_call_detection->SetInputCtrlParamTuple("height_offset", height_offset);

//        m_call_detection->SetInputCtrlParamTuple("row1", row1);
//        m_call_detection->SetInputCtrlParamTuple("column1", column1);
//        m_call_detection->SetInputCtrlParamTuple("row2", row2);
//        m_call_detection->SetInputCtrlParamTuple("column2", column2);
//        m_call_detection->SetInputCtrlParamTuple("r_low", r_low);
//        m_call_detection->SetInputCtrlParamTuple("channel1_high", channel1_high);
//        m_call_detection->SetInputCtrlParamTuple("channel2_low", channel2_low);
//        m_call_detection->SetInputCtrlParamTuple("channel2_high", channel2_high);
//        m_call_detection->SetInputCtrlParamTuple("channel3_low", channel3_low);
//        m_call_detection->SetInputCtrlParamTuple("channel3_high", channel3_high);



       

        // Execute the procedure

//        HDevEngine().StartDebugServer();
//        m_call_detection->SetWaitForDebugConnection(true);
//        m_call_detection->Execute();
//        HDevEngine().StopDebugServer();

//        region_error= m_call_detection->GetOutputIconicParamObject("region_error");

        
        // get the output parameters
//        HTuple ret = m_call_detection->GetOutputCtrlParamTuple(1);
//        HTuple msg = m_call_detection->GetOutputCtrlParamTuple(2);
//        HTuple size_error = m_call_detection->GetOutputCtrlParamTuple(3);




        m_result = ret[0].I();



        m_size_error_now  = size_error[0].D();



        if(m_size_error_now>=m_area_low)
        {

            if(m_size_error_now>=m_area_high)
            {
                message = "OK" + QString::number(m_size_error_now) +"检测面积大于缺陷面积上限";
                return true;
            }
            else
            {
                message = "NG缺陷" + QString::number(m_size_error_now) +"检测面积大于缺陷面积下限";
                return false;
            }

        }



        return true;

    }

    catch (const HalconCpp::HOperatorException& hdev_exception)
    {
        message = hdev_exception.ErrorMessage();
        return false;
    }
//    message = "HSV OK";
    return true;
}


void DetectionThreshold::detectionImage()
{
    QString message;
    detection(image_in,message);

    Mat image_show = himageToMat(image_in);
    draw(image_show, image_show);

    QImage q_image = matToQImage(image_show);
    m_view->setImage(q_image, message);
}

void DetectionThreshold::testImage()
{
    QString message;
    detection(image_in,message);

    Mat image_show = himageToMat(image_in);
    image_show  = Mat::zeros(Size(image_show.cols,image_show.rows),CV_8UC3);
    draw(image_show, image_show);

    QImage q_image = matToQImage(image_show);
    m_view->setImage(q_image, message);
}

void DetectionThreshold::draw(Mat image_in,Mat& image_out)
{
    if(image_in.empty())
        return;
    image_out = drawRegionFill(image_in, region_error, Scalar(0, 0, 255));
    GenEmptyRegion(&region_error);
}

void DetectionThreshold::loadParameter()
{
    row1 = m_qsettings->value(m_section + "/" + "row1",100).toInt();
    column1 = m_qsettings->value(m_section + "/" + "column1",100).toInt();
    row2 = m_qsettings->value(m_section + "/" + "row2",200).toInt();
    column2 = m_qsettings->value(m_section + "/" + "column2",200).toInt();

    m_view->setRectPose(row1, column1, row2, column2);


    m_area_low = m_qsettings->value(m_section + "/" + "m_area_low").toInt();
    m_area_high = m_qsettings->value(m_section + "/" + "m_area_high").toInt();
    m_rgb_hsv = m_qsettings->value(m_section + "/" + "m_rgb_hsv").toInt();
    m_no_yes_mask = m_qsettings->value(m_section + "/" + "m_no_yes_mask").toInt();
    m_mask_low = m_qsettings->value(m_section + "/" + "m_mask_low").toInt();
    channel1_low = m_qsettings->value(m_section + "/" + "channel1_low").toInt();
    channel1_high = m_qsettings->value(m_section + "/" + "channel1_high").toInt();
    channel2_low = m_qsettings->value(m_section + "/" + "channel2_low").toInt();
    channel2_high = m_qsettings->value(m_section + "/" + "channel2_high").toInt();
    channel3_low = m_qsettings->value(m_section + "/" + "channel3_low").toInt();
    channel3_high = m_qsettings->value(m_section + "/" + "channel3_high").toInt();

    m_qspinbox_area_low->setValue(m_area_low);
    m_qspinbox_area_high->setValue(m_area_high);

    m_qcombobox_rgb_hsv->setCurrentIndex(m_rgb_hsv);
    m_qcombobox_no_yes_mask->setCurrentIndex(m_no_yes_mask);

    m_qspinbox_mask_low->setValue(m_mask_low);
    m_qslider_mask_low->setValue(m_mask_low);

    m_qspinbox_channel1_low->setValue(channel1_low);
    m_qslider_channel1_low->setValue(channel1_low);

    m_qspinbox_channel2_low->setValue(channel2_low);
    m_qslider_channel2_low->setValue(channel2_low);

    m_qspinbox_channel3_low->setValue(channel3_low);
    m_qslider_channel3_low->setValue(channel3_low);

    m_qspinbox_channel2_high->setValue(channel1_high);
    m_qslider_channel2_high->setValue(channel1_high);

    m_qspinbox_channel1_high->setValue(channel2_high);
    m_qslider_channel1_high->setValue(channel2_high);

    m_qspinbox_channel3_high->setValue(channel3_high);
    m_qslider_channel3_high->setValue(channel3_high);


    return ;
}

void DetectionThreshold::saveParameter()
{


    QRectF qrectf = m_view->m_graphics_shape_rect->boundingRect();
    row1 = m_view->m_graphics_shape_rect->pos().y() + (int)qrectf.y();
    column1 = m_view->m_graphics_shape_rect->pos().x() + (int)qrectf.x();
    row2 = m_view->m_graphics_shape_rect->pos().y() + (int)(qrectf.y() + qrectf.height());
    column2 = m_view->m_graphics_shape_rect->pos().x() + (int)(qrectf.x() + qrectf.width());

    m_qsettings->setValue(m_section + "/" + "row1", row1);
    m_qsettings->setValue(m_section + "/" + "column1", column1);
    m_qsettings->setValue(m_section + "/" + "row2", row2);
    m_qsettings->setValue(m_section + "/" + "column2", column2);

    m_area_low = m_qspinbox_area_low->value();
    m_area_high = m_qspinbox_area_high->value();

    m_rgb_hsv = m_qcombobox_rgb_hsv->currentIndex();
    m_no_yes_mask = m_qcombobox_no_yes_mask->currentIndex();
    m_mask_low = m_qslider_mask_low->value();
    channel1_low = m_qslider_channel1_low->value();
    channel1_high = m_qslider_channel1_high->value();
    channel2_low = m_qslider_channel2_low->value();
    channel2_high = m_qslider_channel2_high->value();
    channel3_low = m_qslider_channel3_low->value();
    channel3_high = m_qslider_channel3_high->value();

    m_qsettings->setValue(m_section + "/" + "m_area_low", m_area_low);
    m_qsettings->setValue(m_section + "/" + "m_area_high", m_area_high);


    m_qsettings->setValue(m_section + "/" + "m_rgb_hsv", m_rgb_hsv);
    m_qsettings->setValue(m_section + "/" + "m_no_yes_mask", m_no_yes_mask);
    m_qsettings->setValue(m_section + "/" + "m_mask_low", m_mask_low);
    m_qsettings->setValue(m_section + "/" + "channel1_low", channel1_low);
    m_qsettings->setValue(m_section + "/" + "channel1_high", channel1_high);
    m_qsettings->setValue(m_section + "/" + "channel2_low", channel2_low);
    m_qsettings->setValue(m_section + "/" + "channel2_high", channel2_high);
    m_qsettings->setValue(m_section + "/" + "channel3_low", channel3_low);
    m_qsettings->setValue(m_section + "/" + "channel3_high", channel3_high);


}

bool DetectionThreshold::showDialog()
{
    Mat image_show = himageToMat(image_in);
    QImage q_image = matToQImage(image_show);
    m_view->setImage(q_image,"");
    return true;
}


